"""
fastapi 服务
"""
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from loguru import logger
from pathlib import Path

log_dir = Path(__file__).parent / "logs"
logger.add(log_dir / "info.log",  level='INFO',  rotation="50 MB",   retention="10 days")
logger.add(log_dir / "debug.log", level='DEBUG', rotation="500 MB",  retention="10 days")
logger.add(log_dir / "error.log", level='ERROR', rotation="50 MB",   retention="10 days")


def create_app():
    app = FastAPI(title="Eastern Translate API Server", version='1.0')
    app.add_middleware(
        CORSMiddleware,
        allow_origins=["*"],
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )
    mount_chat_routes(app)
    return app


def mount_chat_routes(app: FastAPI):

    from services.cls_api import classify_api

    app.post(
        path='/class', summary="东盟文本分类"
    )(classify_api)

my_app = create_app()


if __name__ == '__main__':
    uvicorn.run(app=my_app, host="0.0.0.0", port=6006, reload=False)
